﻿@*------------------------------------------------------------
  Copyright (c) Microsoft Corporation.  All rights reserved.
  Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
------------------------------------------------------------*@

@page "/gateways"

@using Microsoft.AspNetCore.Components;
@using Microsoft.Azure.IIoT.App.Services;
@using Microsoft.Azure.IIoT.App.Components.Buttons;
@using Microsoft.Azure.IIoT.App.Components.ErrorMessage;
@using Microsoft.Azure.IIoT.App.Components.Loader;
@using Microsoft.Azure.IIoT.OpcUa.Api.Registry;
@using Microsoft.Azure.IIoT.OpcUa.Api.Registry.Models; 
@using Microsoft.Azure.IIoT.App.Common;
@using Microsoft.Azure.IIoT.App.Components.Icons;
@using Microsoft.Azure.IIoT.App.Models;

@inject NavigationManager NavigationManager
@inject Registry RegistryHelper
@inject IRegistryServiceApi RegistryService
@inject RegistryServiceEvents RegistryServiceEvents
@inject UICommon CommonHelper

@inherits IIoTItemsCollection<GatewayApiModel>


<h1>Gateways</h1>

<table class="table table-responsive @_tableView">
    <thead>
        <tr>
            <th class="width-x-large">Id</th>
            <th class="width-large">Site Id</th>
            <th class="width-large">Connection Status</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var gateway in Items.Results)
        {
            <tr>
                <td class="hover-text width-x-large">
                    <div>
                        @gateway.Id
                    </div>
                </td>
                <td class="hover-text width-large">
                    <div>
                        @(string.IsNullOrEmpty(gateway.SiteId)
                            ? CommonHelper.None
                            : gateway.SiteId)
                    </div>
                </td>
                @{string connectStatus = gateway.Connected == null
                                ? CommonHelper.None
                                : gateway.Connected == true
                                    ? "Connected"
                                    : "Disconnected";}
                <td class="hover-text width-large">
                    <ConnectStatus Status="@connectStatus" />
                </td>
            </tr>
        }
    </tbody>
</table>
<div class="@_tableEmpty center">No Gateways found.</div>

<ErrorMessage PageError="@Items.Error" Status="@null"></ErrorMessage>

<LoadMore Result=@Items IsLoading=@IsLoading LoadMoreItems=@(async() => await LoadMoreItems()) />

<Spinner IsLoading=@IsLoading></Spinner>